package com.lancoo.znbkxx.teacher.ui.adapter

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.activity.ComponentActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassVocablaryDiagnosisInfor
import com.lancoo.znbkxx.teacher.utils.ButtonUtils
import com.lancoo.znbkxx.teacher.utils.DensityUtils
import kotlinx.android.synthetic.main.aibk_adapter_item_read_vocabulary_count.view.*

class AibkReadVocabularyCountAdapter(
        val activity: ComponentActivity?,
        val maxStuNum:Int,
        val classVocablaryDiagnosisInfor: ClassVocablaryDiagnosisInfor
): KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_read_vocabulary_count, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        var subsetName = ""//区间
        var masterStuNum = 0//人数
        if(position == 0){
             subsetName = classVocablaryDiagnosisInfor.LVList[1].VocabMap[2].SubsetName
             masterStuNum = classVocablaryDiagnosisInfor.LVList[1].VocabMap[2].MasterStuNum
            holder.convertView.TvReadBottomTitle1.text = "掌握较好"
            holder.convertView.TvReadBottomTitle1.setTextColor(Color.parseColor("#00afff"))
            holder.convertView.TvReadBottomTitle2.setTextColor(Color.parseColor("#00afff"))
        }else if(position == 1){
             subsetName = classVocablaryDiagnosisInfor.LVList[1].VocabMap[1].SubsetName
             masterStuNum = classVocablaryDiagnosisInfor.LVList[1].VocabMap[1].MasterStuNum
            holder.convertView.TvReadBottomTitle1.text = "掌握一般"
            holder.convertView.TvReadBottomTitle1.setTextColor(Color.parseColor("#22d7bb"))
            holder.convertView.TvReadBottomTitle2.setTextColor(Color.parseColor("#22d7bb"))
        }else if(position == 2){
             subsetName = classVocablaryDiagnosisInfor.LVList[1].VocabMap[0].SubsetName
             masterStuNum = classVocablaryDiagnosisInfor.LVList[1].VocabMap[0].MasterStuNum
            holder.convertView.TvReadBottomTitle1.text = "掌握较差"
            holder.convertView.TvReadBottomTitle1.setTextColor(Color.parseColor("#f9ad4f"))
            holder.convertView.TvReadBottomTitle2.setTextColor(Color.parseColor("#f9ad4f"))
        }
        holder.convertView.TvReadBottomTitle2.text = subsetName
        holder.convertView.TvReadVocabularyCount.text = masterStuNum.toString()+"人"
        showIvData(holder.convertView.IvReadVocabularyCount,masterStuNum)
        holder.convertView.LlReadAbilityView.setOnClickListener {
            if(masterStuNum == 0){
                return@setOnClickListener
            }
            var flag = 0
            if(position == 0){
                flag = 2
            }else if(position == 1){
                flag = 1
            }else if(position == 2){
                flag = 0
            }
            if (!ButtonUtils.isFastDoubleClick(R.id.IvReadVocabularyCount)) {
                clickListener!!.onClick(flag)
            }
        }
    }

    override fun getItemCount(): Int {
        return 3
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    private fun showIvData(Iv: ImageView, data:Int){
        val para1 = Iv.layoutParams
        para1.width = DensityUtils.dp2px(activity,(data*70f)/maxStuNum)
        Iv.layoutParams = para1
    }

    interface OnClickListener {
        fun onClick(flag:Int)
    }

    private var clickListener: OnClickListener? = null

    fun setClickListener(clickListener: OnClickListener?) {
        this.clickListener = clickListener
    }

}